Vue Js JSON.stringify(): Vue.js provides a built-in method called JSON.stringify(), which can be used to serialise JavaScript or objects into a JSON string representation. Here in this tutorial, we will learn how to convert a JSON object to a JSON string with the help of native Javascript and Vue JS.
Vue Js JSON.stringify() Method Synatax
this.testString = JSON.stringify(this.testObj);
How to convert a JSON object to a string using Vue.js
In Vue.js, the JSON object can be converted to a string by using the “JSON.stringify()” function.With the our online editor, you can easily customize your code and see the results of your changes in real-time
Vue Js JSON.stringify() Method | Example
<div id="app">
<button @click="myFunction">click me</button>
<p>String:{{testString}}</p>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data()
{
return{
testObj:{firstName: 'Andrew',lastName:'Roy',role:'developer'},
testString:''
}
},
methods:{
myFunction(){
this.testString = JSON.stringify(this.testObj);
},
}
}).mount('#app')
</script>